use "build/output/main_panel.dta", clear

local m = 0.2
gen rho = funding_apr - (1-`m')*margin_aprFTX
gen rho_bps = rho*100

sort coin date
tsset coin_id date

gen d_rho = d.rho

eststo clear

eststo: reg d.rho_bps d_ln_face_bps if coin == "USDT", vce(cluster wdate)
estadd local month_fe "No"
estadd local coin_fe "n/a"

eststo: reg d.rho_bps d_ln_face_bps i.mdate if coin == "USDT", vce(cluster wdate)
estadd local month_fe "Yes"
estadd local coin_fe "n/a"

eststo: reg d.rho_bps d_ln_face_bps iv_btc i.mdate l.d_ln_face_bps l.ln_face if coin == "USDT", vce(cluster wdate)
estadd local month_fe "Yes"
estadd local coin_fe "n/a"

eststo: reg d.rho_bps d_ln_face_bps, vce(cluster wdate)
estadd local month_fe "No"
estadd local coin_fe "No"

eststo: reg d.rho_bps d_ln_face_bps i.mdate i.coin_id, vce(cluster wdate)
estadd local month_fe "Yes"
estadd local coin_fe "Yes"

eststo: reg d.rho_bps d_ln_face_bps iv_btc i.mdate l.d_ln_face_bps l.ln_face i.coin_id, vce(cluster wdate)
estadd local month_fe "Yes"
estadd local coin_fe "Yes"

esttab, drop(*.mdate *.coin_id _cons) star(* 0.10 ** 0.05 *** 0.01) ar2

esttab using "analysis/output_tables/regression_rho.tex", replace booktabs label drop(*.mdate *.coin_id _cons) ///
	mgroups("USDT" "USDT and DAI", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	prehead(\begin{tabular}{l S S S S S S}   \toprule) ///
	posthead(\midrule) postfoot(\bottomrule\end{tabular}) ///
	style(tex) substitute(\_ _) star  b(2) t(2) r2(2) ///
	nomtitles /// 
	varlabels(iv_btc "\$\text{Bitcoin Implied Volatility}_{t}\$" d_ln_face_bps "\$\Delta \ln(s_{i,t})\$" ln_face "\$\ln(s_{i,t})\$" L.d_ln_face_bps "\$\Delta \ln(s_{i,t-1})\$" L.ln_face "\$\ln(s_{i,t-1})\$") /// 
	star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2 month_fe coin_fe, fmt(%9.0fc 2) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") labels(`"\$N\$"' `"\(R^{2}\)"' `"Month FE"' `"Coin FE"' ))



	
	